package com.ruoyi.carowner.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carowner.domain.CarownerRule;
import com.ruoyi.carowner.service.ICarownerRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 兑换规则Controller
 * 
 * @author aa
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/carowner/rule")
public class CarownerRuleController extends BaseController
{
    @Autowired
    private ICarownerRuleService carownerRuleService;

    /**
     * 查询兑换规则列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerRule carownerRule)
    {
        startPage();
        List<CarownerRule> list = carownerRuleService.selectCarownerRuleList(carownerRule);
        return getDataTable(list);
    }

    /**
     * 导出兑换规则列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:rule:export')")
    @Log(title = "兑换规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerRule carownerRule)
    {
        List<CarownerRule> list = carownerRuleService.selectCarownerRuleList(carownerRule);
        ExcelUtil<CarownerRule> util = new ExcelUtil<CarownerRule>(CarownerRule.class);
        util.exportExcel(response, list, "兑换规则数据");
    }

    /**
     * 获取兑换规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('carowner:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(carownerRuleService.selectCarownerRuleById(id));
    }

    /**
     * 新增兑换规则
     */
    @PreAuthorize("@ss.hasPermi('carowner:rule:add')")
    @Log(title = "兑换规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerRule carownerRule)
    {
        return toAjax(carownerRuleService.insertCarownerRule(carownerRule));
    }

    /**
     * 修改兑换规则
     */
    @PreAuthorize("@ss.hasPermi('carowner:rule:edit')")
    @Log(title = "兑换规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerRule carownerRule)
    {
        return toAjax(carownerRuleService.updateCarownerRule(carownerRule));
    }

    /**
     * 删除兑换规则
     */
    @PreAuthorize("@ss.hasPermi('carowner:rule:remove')")
    @Log(title = "兑换规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(carownerRuleService.deleteCarownerRuleByIds(ids));
    }
}
